﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPFWebControl
{
    public partial class MainWindow : System.Windows.Window, INotifyPropertyChanged
    {


        private void StartWaitConfirmThread()
        {
            assignProcess(runAfterClick, startSenKey);
        }

        const int WM_KEYDOWN = 0x0100;
        const int VK_RETURN = 0x0D;
        const int SW_HIDE = 0x06;
        bool m_start_enter = false;
        private void runAfterClick(Object sender, DoWorkEventArgs e)
        {
            while (true)
            {
                //"Windows Internet Explorer"
                IntPtr zero = IntPtr.Zero;
                zero = FindWindow(null, "Windows Internet Explorer");
                if (zero != IntPtr.Zero)
                {
                    ShowWindow(zero, SW_HIDE);
                    System.Collections.Generic.List<IntPtr> listHwnd = GetAllChildrenWindowHandles(zero, 100);
                    foreach (IntPtr item in listHwnd)
                    {
                        System.Collections.Generic.List<IntPtr> listSubHwnd = GetAllChildrenWindowHandles(item, 100);
                        foreach (IntPtr Subitem in listSubHwnd)
                        {
                            System.Collections.Generic.List<IntPtr> listSubSubHwnd = GetAllChildrenWindowHandles(Subitem, 100);
                            foreach (IntPtr SubSubitem in listSubSubHwnd)
                            {
                                string str = GetWindowCaption(SubSubitem);
                                if (str == "&Leave this page")
                                {
                                    PostMessage(SubSubitem, 0x0100, 0x0D, 1);
                                    m_start_enter = true;
                                }
                            }
                        }
                    }

                }
                else if (m_start_enter)
                {
                    m_start_enter = false;
                    break;
                }
            }

        }
    }
}
